import 'package:app/pages/login_modules/code_login_module/code_login_view.dart';
import 'package:app/pages/login_modules/forget_password_module/forget_password_view.dart';
import 'package:app/pages/login_modules/login_controller.dart';
import 'package:app/pages/login_modules/seturl_page.dart';
import 'package:app/utils/search_module.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:get/get.dart';

import '../../common/colors.dart';
import '../../components/custom_indicator.dart';
import '../../components/gradient_button.dart';
import '../../components/my_webview.dart';
import '../../router/app_pages.dart';
import '../mine_module/serve_setting_page.dart';

class LoginView extends GetView{

  LoginController controller = Get.put(LoginController());

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
        resizeToAvoidBottomInset: false,
        body:GetBuilder<LoginController>(builder: (_){
          return GestureDetector(
            onTap: (){
              SearchModule.closeKeyboard(context);
            },
            child: Stack(
              children: [
                Image.asset('images/login_bg.png',width: Get.width,height: Get.height,fit: BoxFit.cover,),
                Container(
                  color: Colors.black54,
                ),
                Container(
                  margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top+5),
                  height: 50,
                  width: Get.width,
                  // color: Colors.red,
                  alignment: Alignment.centerRight,
                  child: IconButton(onPressed: (){
                    Get.to(ServeSettingPage());
                    // Get.to(SetUrlPage());
                  }, icon: Icon(Icons.settings,color: Colors.white,size: 20,)),
                ),
                Container(

                  margin: const EdgeInsets.only(top: 100),
                  child:Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        // color: Colors.red,
                          padding: const EdgeInsets.only(top: 25, left: 15, right: 15),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: [
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Row(
                                    children: [
                                      ///gengx
                                      Image.asset(
                                        'images/log_icon.png',
                                        width: 50,
                                        height: 50,
                                        // package: 'flutter_public_widget',
                                      ),
                                      Container(
                                        margin: const EdgeInsets.only(left: 8),
                                        child: Text(
                                          '登录DTCloud-APP'.tr,
                                          style: const TextStyle(
                                              fontSize: 22,
                                              color: Colors.white,
                                              fontWeight: FontWeight.w600),
                                        ),
                                      )
                                    ],
                                  )
                                  // Container(
                                  //   margin: EdgeInsets.only(top: 5),
                                  //   child: Text(
                                  //     '海量教学课程,视频',
                                  //     style: TextStyle(
                                  //         fontSize: 12,
                                  //         color: HexColor('#999999'),
                                  //         fontWeight: FontWeight.w400),
                                  //   ),
                                  // )
                                ],
                              ),
                              // Image.asset(A.assets_loginright)
                            ],
                          )),
                      Expanded(
                          child: Column(
                            children: [
                              Container(
                                margin: const EdgeInsets.only(top: 15),
                                width: Get.width,
                                decoration: BoxDecoration(
                                  color: Colors.transparent,
                                  borderRadius: BorderRadius.circular(0.0),
                                ),
                                child: TabBar(
                                  isScrollable: true,
                                  controller: controller.tabController,

                                  labelStyle: const TextStyle(
                                    fontSize: 15,),

                                  labelColor: Theme.of(context).primaryColor,

                                  unselectedLabelStyle:
                                  const TextStyle(fontSize: 14,),
                                  unselectedLabelColor: Colors.white,
                                  indicatorSize: TabBarIndicatorSize.label,

                                  indicator: UnderlineTabIndicatorLi(
                                      borderSide: BorderSide(
                                          color: Theme.of(context).primaryColor,
                                          width: 2,
                                          style: BorderStyle.solid)),
                                  // indicatorColor: HexColor('#567BFD'),

                                  tabs: [
                                    Tab(
                                      text: '账号登录'.tr,
                                    ),
                                    Tab(
                                      text: '验证码登录'.tr,
                                    ),
                                  ],
                                ),
                              ),
                              Expanded(
                                child: TabBarView(
                                  controller: controller.tabController,
                                  children: [
                                    ListView(
                                      children: [
                                        Center(
                                          child: Container(
                                            decoration: BoxDecoration(
                                              color: Colors.transparent,
                                              //设置四周圆角 角度
                                              borderRadius: const BorderRadius.all(
                                                  Radius.circular(25.0)),
                                              //设置四周边框
                                              border: Border.all(
                                                  width: 0.5, color: Colors.white),
                                            ),
                                            padding: const EdgeInsets.only(left: 15),
                                            margin: const EdgeInsets.only(
                                                top: 20, left: 15, right: 15),
                                            // width: Get.width-100,
                                            child: TextField(
                                              controller: controller.usernameTF,
                                              autofocus: true,
                                              style: const TextStyle(fontSize: 16,color: Colors.white),
                                              inputFormatters: <TextInputFormatter>[
                                                LengthLimitingTextInputFormatter(13) //限制长度
                                              ],
                                              decoration: InputDecoration(
                                                // isCollapsed: true,
                                                // contentPadding: EdgeInsets.only(top: 15),
                                                hintText: '请输入账号/手机号'.tr,
                                                hintStyle: TextStyle(
                                                    fontSize: 16, color: Colors.white.withAlpha(50)),
                                                border: InputBorder.none,
                                                // prefixIcon: Image.asset(A.assets_user,),
                                              ),
                                            ),
                                          ),
                                        ),
                                        Center(
                                          child: Container(
                                              decoration: BoxDecoration(
//背景
                                                color: Colors.transparent,
                                                //设置四周圆角 角度
                                                borderRadius: const BorderRadius.all(
                                                    Radius.circular(25.0)),
                                                //设置四周边框
                                                border: Border.all(
                                                    width: 0.5, color: Colors.white),
                                              ),
                                              padding: const EdgeInsets.only(left: 15),
                                              margin: const EdgeInsets.only(
                                                  top: 10, right: 15, left: 15),
                                              child: Row(
                                                children: [
                                                  SizedBox(
                                                    width: Get.width - 100,
                                                    child: TextField(
                                                      keyboardType: TextInputType.visiblePassword,
                                                      obscureText: controller.displayPsw,
                                                      controller: controller.passwordTF,
                                                      style: const TextStyle(fontSize: 16,color: Colors.white),
                                                      inputFormatters: <TextInputFormatter>[
                                                        // WhitelistingTextInputFormatter.digitsOnly,//只输入数字
                                                        LengthLimitingTextInputFormatter(
                                                            16) //限制长度
                                                      ],
                                                      decoration: InputDecoration(
                                                        // contentPadding: EdgeInsets.only(top: 15),
                                                        hintText: '请输入密码'.tr,
                                                        hintStyle: TextStyle(
                                                            fontSize: 16,
                                                            color: Colors.white.withAlpha(50)),
                                                        border: InputBorder.none,
                                                        // prefixIcon: Image.asset(A.assets_pwd),
                                                      ),
                                                    ),
                                                  ),
                                                  IconButton(
                                                      onPressed: () {
                                                        controller.tapClickPasswordShow();
                                                      },
                                                      icon: Image.asset(
                                                        'images/showps.png',
                                                        width: 15,
                                                        height: 15,
                                                        // package: 'flutter_public_widget',
                                                      ))
                                                ],
                                              )),
                                        ),

                                        /// 记住密码
                                        Container(
                                          alignment: Alignment.center,
                                          // color: Colors.red,
                                          margin: EdgeInsets.only(top: 25,left: 25,),
                                          child:  Row(
                                            children: [
                                              GestureDetector(
                                                onTap: (){
                                                  // isRememberPs=!isRememberPs;
                                                  // if(isRememberPs == true){
                                                  //   getUsernameAndPassWord();
                                                  // }else{
                                                  //   clearUserNameAndPassWord();
                                                  // }
                                                  //
                                                  // setState(() {});
                                                  controller.tapClickRememberPassWord();
                                                },
                                                child: Container(
                                                  child:controller.isRememberPs==true?Image.asset('images/check_sel.png',width: 15,
                                                    height: 15,color: AppColor.themeColor,):Image.asset('images/check_normal.png',width: 15,
                                                    height: 15,),
                                                ),
                                              ),
                                              SizedBox(width: 5,),
                                              Text('记住密码',style: TextStyle(color: Colors.white),)
                                            ],
                                          ),

                                          // Row(
                                          //   mainAxisAlignment: MainAxisAlignment.center,
                                          //   children: [
                                          //     Text(
                                          //       '阅读',
                                          //       style: TextStyle(
                                          //           fontSize: 12, color: HexColor('#333333')),
                                          //     ),
                                          //     GestureDetector(
                                          //       onTap: () {
                                          //         // Get.to();
                                          //       },
                                          //       child: Text(
                                          //         '《用户协议》《个人信息保护政策》',
                                          //         style: TextStyle(
                                          //             fontSize: 12,
                                          //             color: Theme.of(context).primaryColor),
                                          //       ),
                                          //     )
                                          //   ],
                                          // ),
                                        ),

                                 Align(
                                   alignment: Alignment.centerLeft,
                                   child:GestureDetector(
                                   onTap: (){
                                     // Get.to( ForgetPasswordView());
                                     Get.toNamed('${AppRoutes.forgetPass}');
                                   },
                                   child:Container(
                                     // width: 100,
                                     // color: Colors.yellow,
                                     margin: const EdgeInsets.only(top: 10,left: 25),
                                     child: const Text('忘记密码?',
                                       style: TextStyle(color: Colors.white,
                                           fontSize: 14
                                       ),),
                                     // color: Colors.red,
                                   ),
                                 ),),

                                        // GestureDetector(
                                        //   child: Container(
                                        //     padding: EdgeInsets.only(left: 25,top: 15,right: 25),
                                        //     // color: Colors.red,
                                        //     child: Row(
                                        //       mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                        //       children: [
                                        //         Text('注册账号'.tr,style: TextStyle(fontSize: 14,color: HexColor('#2A39E1')),),
                                        //         Text('帮助手册'.tr,style: TextStyle(fontSize: 14,color: HexColor('#2A39E1')),),
                                        //       ],
                                        //     ),
                                        //
                                        //   ),
                                        //   onTap: (){
                                        //     Get.to(RegisterPage());
                                        //   },
                                        // ),

                                        Container(
                                          padding:
                                          const EdgeInsets.only(left: 25, top: 15, right: 25),
                                          // color: Colors.red,
                                          child: Row(
                                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                            children: [
                                              GestureDetector(
                                                child: Text(
                                                  '注册账号'.tr,
                                                  style: const TextStyle(
                                                      fontSize: 14,
                                                      color: Colors.white),
                                                ),
                                                onTap: () {
                                                  // Get.to(const RegisterPage());
                                                  Get.toNamed(AppRoutes.register);
                                                },
                                              ),
                                              // GestureDetector(
                                              //
                                              //   child:  Text('手势登录'.tr,style: TextStyle(fontSize: 14,color: HexColor('#2A39E1')),),
                                              //   onTap: (){
                                              //     // Get.to(gesture_page());
                                              //     Get.to(GesturePasswordWidgetDemo());
                                              //   },
                                              // ),
                                              //  GestureDetector(
                                              //
                                              //    child:  Text('人脸登录'.tr,style: TextStyle(fontSize: 14,color: HexColor('#2A39E1')),),
                                              //    onTap: (){
                                              //      // Get.to(gesture_page());
                                              //      Get.to(FaceLoginPage());
                                              //      // Get.to(GesturePasswordWidgetDemo());
                                              //    },
                                              //  ),
                                              GestureDetector(
                                                child: Text(
                                                  '帮助手册'.tr,
                                                  style: const TextStyle(
                                                      fontSize: 14,
                                                      color: Colors.white),
                                                ),
                                                onTap: () {
                                                  // Get.to(MyWebView(title: '使用说明',url: 'https://docs.qq.com/doc/DZmFZYVVKTldOQ3dp',));
                                                  Get.to(MyWebView('使用说明',
                                                      'https://docs.qq.com/doc/DZmFZYVVKTldOQ3dp'));
                                                },
                                              )
                                            ],
                                          ),
                                        ),

                                        Container(
                                          margin:
                                          const EdgeInsets.only(top: 62, right: 15, left: 15),
                                          width: Get.width,
                                          height: 45,
                                          child: GradientButton(child: Text('登录'),onPressed: (){
                                            controller.tapClickLoginBtn();
                                          },borderRadius: BorderRadius.all(Radius.circular(20)),),
                                          // MaterialButton(
                                          //   elevation: 0,
                                          //   shape: RoundedRectangleBorder(
                                          //     borderRadius: BorderRadius.circular(22),
                                          //   ),
                                          //   color: AppColor.themeColor,
                                          //   onPressed: () => controller.tapClickLoginBtn(),
                                          //   child: Text(
                                          //     '登录'.tr,
                                          //     style: const TextStyle(color: Colors.white),
                                          //   ),
                                          // ),
                                        ),

                                        Container(
                                          // color: Colors.red,
                                          margin: const EdgeInsets.only(top: 25),
                                          child: Row(
                                            mainAxisAlignment: MainAxisAlignment.center,
                                            children: [
                                              const Text(
                                                '阅读',
                                                style: TextStyle(
                                                    fontSize: 12, color: Colors.white),
                                              ),
                                              GestureDetector(
                                                onTap: () {
                                                  // Get.to();
                                                  Get.to(MyWebView('', 'https://docs.qq.com/doc/DUUZSZW5la3FySVhP'));
                                                },
                                                child: Text(
                                                  '《用户协议》《个人信息保护政策》',
                                                  style: TextStyle(
                                                      fontSize: 12,
                                                      color: Theme.of(context).primaryColor),
                                                ),
                                              )
                                            ],
                                          ),
                                        )
                                      ],
                                    ),
                                    CodeLoginView(),
                                    // Container(),
                                  ],
                                ),
                              ),
                            ],
                          )
                      )
                    ],
                  ),
                ),
              ],
            ),
          );
        })
    );
  }
  
}